package com.shr.xsunmvc.route;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

/**
 * 路由管理器，用于管Route对象
 * @author sun haoran
 *
 */
public class Routers {
	private static final Logger LOGGER = Logger.getLogger(Routers.class.getName()) ;
	
	/**
	 * 用于存放Route对象的list
	 */
	private List<Route> routeList = new ArrayList<>();
	
	public void addRoute(List<Route> routeList){
		this.routeList.addAll(routeList);
	}
	
	public void addRoute(Route route){
		this.routeList.add(route);
	}
	
	public void removeRoute(Route route){
		this.routeList.remove(route);
	}
	
	public void addRoute(String path, Method action, Object controller){
		Route route = new Route();
		route.setController(controller);
		route.setMethod(action);
		route.setPath(path);
		
		this.routeList.add(route);
		LOGGER.info("Add route [" + path + "]");
	}
	
	public List<Route> getRoutes(){
		return routeList;
	}
	
	public void setRoutes(List<Route> routes){
		this.routeList = routes ;
	}
}
